package com.hongkzh.www.sys;

import com.hongkzh.www.conmon.FileHandler;
import com.hongkzh.www.conmon.MyRenderFactory;
import com.hongkzh.www.routes.V1Routes;
import com.hongkzh.www.swagger.config.routes.SwaggerRoutes;
import com.jfinal.config.*;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;

import java.io.File;

/**
 * @author martins
 */
public class SystemConfig  extends JFinalConfig {
    @Override
    public void configConstant(Constants me) {

        PropKit.use("a_little_config.txt");
        me.setDevMode(PropKit.getBoolean("devMode", false));
        me.setBaseUploadPath(PropKit.get("userfiles.basedir"));
        me.setBaseDownloadPath(PropKit.get("userfiles.basedir"));
         me.setRenderFactory(new MyRenderFactory());
        //PathKit.
    }
    @Override
    public void configRoute(Routes me) {

        me.add(new V1Routes());
        me.add(new SwaggerRoutes());

    }
    @Override
    public void configEngine(Engine me) {}
    @Override
    public void configPlugin(Plugins me) {
        // 配置 druid 数据库连接池插件
        DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbc.url"), PropKit.get("jdbc.username"), PropKit.get("jdbc.password").trim());
        me.add(druidPlugin);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        //arp.getEngine().setSourceFactory(new ClassPathSourceFactory());
        arp.setBaseSqlTemplatePath(PathKit.getRootClassPath()+ File.separator+"sql");
        arp.setDevMode(true);
        arp.setShowSql(true);
        arp.addSqlTemplate("all.sql");

        me.add(arp);
       /* RedisPlugin redis = new RedisPlugin("redis", "localhost",7777,"hkzh713p@ssw0rd2");
        redis.getJedisPoolConfig()
        me.add(redis);*/
    }
    @Override
    public void configInterceptor(Interceptors me) {}
    @Override
    public void configHandler(Handlers me) {
        me.add(new FileHandler());
    }
    public static DruidPlugin createDruidPlugin() {
        return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
    }
}